import {nanoid} from "nanoid";

/**
 * 位置信息
 */
export interface ComponentAttr {
    x: number
    y: number
    width: number
    height: number
}

/**
 * 设置信息
 */
export interface ComponentConfig {
    isEdit: boolean
    dragable: boolean
    resizable: boolean
}

/**
 * 组件
 */
export abstract class QYComponent {
    id: string
    readonly name: string
    readonly type: string
    title:string
    itemType:0
    isSelect: false//是否选中 前端所需
    attr:ComponentAttr={
        x: 10,
        y: 10,
        width: 90,
        height: 20,
    }
    config:ComponentConfig={
        isEdit: false,
        dragable: true,
        resizable: true
    }
    data:object
    style:object

    constructor(type: string, attr: Partial<ComponentAttr>) {
        this.id = nanoid()
        this.type = type

        this.attr = { ...this.attr, ...attr }
    }
}
